<?php
/**
 * Created by : PhpStorm
 * User: DuFei
 * Date: 2020/8/3
 * Time: 14:04
 */

namespace app\utils;


use Firebase\JWT\JWT;

class JwtUtil
{

    /**
     * @param $payload
     * @param $key
     * @param string $alg
     * @param null $keyId
     * @param null $head
     * @return string
     */
    public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null) {
        return JWT::encode($payload, $key,$alg,$keyId,$head);
    }

    /**
     * @param $jwt
     * @param $key
     * @param array|string[] $allowed_algs
     * @return object|null
     */
    public static function decode($jwt, $key, array $allowed_algs = array('HS256')) {
        return JWT::decode($jwt, $key, $allowed_algs);
    }

}
